package list;

import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author：Jie Ni
 * @Date: 2025/11/1 11:03
 * @Description:
 */
public class TestEqual {

    /**
     * 1.CollectionUtils.isEqualCollection集合里的元素必须覆写equals方法
     * 2.@Data中已经帮我们覆写了equals方法
     * 3.CollectionUtils.isEqualCollection对2个集合中元素的顺序不敏感,顺序不一样
     * 但内容一样也是相同的
     * @param args
     */
    public static void main(String[] args) {
        List<Person> list = new ArrayList<>();
        Person p1 = new Person("lujieni", 34);
        Person p2 = new Person("qiqi", 32);
        list.add(p1);
        list.add(p2);

        List<Person> list2 = new ArrayList<>();
        Person p3 = new Person("lujieni", 34);
        Person p4 = new Person("qiqi", 32);
        list2.add(p4);
        list2.add(p3);

        System.out.println(CollectionUtils.isEqualCollection(list, list2));
    }

    @Data
    private static class Person{

        private String name;

        private Integer age;

        public Person(String name, Integer age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }
    }

}


